package com.hdax.dm.service;

import com.hdax.dm.entity.item.Item;
import com.hdax.dm.entity.item.ItemType;
import com.hdax.dm.feign.base.ImageFeign;
import com.hdax.dm.feign.item.ItemFeign;
import com.hdax.dm.feign.item.ItemTypeFeign;
import com.hdax.dm.vo.FloorVo;
import com.hdax.dm.vo.LineNavVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ItemTypeService {

    @Autowired
    private ItemTypeFeign itemTypeFeign;
    @Autowired
    private ItemFeign itemFeign;
    @Autowired
    private ImageFeign imageFeign;

    public List<LineNavVo> lineNav(){
        List<LineNavVo> lineNavVos = new ArrayList<>();
        List<ItemType> lists = itemTypeFeign.lineNav();
        lists.forEach(list->{
            LineNavVo lineNavVo = new LineNavVo();
            BeanUtils.copyProperties(list,lineNavVo);
            lineNavVo.setItemName(list.getItemType());
            lineNavVos.add(lineNavVo);
        });
        return lineNavVos;
    }

    public List<FloorVo> floor(){
        List<FloorVo> floorVos = new ArrayList<>();
        List<ItemType> floors = itemTypeFeign.floor();
//        for (int i = 1;i<=floors.size();i++){
        final int[] i = {1};
        floors.forEach(floor->{
                FloorVo vo = new FloorVo();
                vo.setIndex(i[0]);
                vo.setItemTypeId(floor.getId());
                vo.setItemTypeName(floor.getItemType());
                List<Item> items = itemFeign.floors(floor.getId());
                List<FloorVo.Items> itemsList = new ArrayList<>();
                items.forEach(item -> {
                    FloorVo.Items items1 = new FloorVo.Items();
                    BeanUtils.copyProperties(item,items1);
                    items1.setAreaId(item.getCinema().getAreaId());
                    items1.setAreaName(item.getCinema().getAreaName());
                    items1.setAddress(item.getCinema().getAddress());
                    items1.setStartDate(item.getStartTime());
                    items1.setEndDate(item.getEndTime());
                    items1.setImgUrl(imageFeign.image(items1.getId(), 2L,1L) == null?"":imageFeign.image(items1.getId(), 2L,1L).getImgUrl());
                    itemsList.add(items1);
                    vo.setItems(itemsList);
                });
                floorVos.add(vo);
                i[0] = i[0] +1;
            });
//        }
        return floorVos;
    }

}
